COUNT
has a 5 stored in it, and:
COUNT <= 5 ^ | +----- holds a 5
is true because 5 is less than or equal to 5.
In general, the DO WHILE
statement looks like this:
DO WHILE condition . . . loop body . . . LOOP
DO
and the LOOP
are brackets
that mark the loop body.WHILE
condition lets execution enter (or re-enter)
the loop body
only if condition is true.So far in these chapters the condition has tested if one number is less than or equal to another number. You can also test if one number is LESS THAN another number:
COUNT < 5
This tests if COUNT
is LESS THAN 5.
Here is the program, slightly modified.
' Loop with LESS THAN test ' LET COUNT = 0 'Statement 1 ' DO WHILE COUNT < 5 'Statement 2 PRINT COUNT 'Statement 3 LET COUNT = COUNT + 1 'Statement 4 LOOP END
Now the DO WHILE
lets execution into the loop body only
if COUNT
is less than (but not equal) to 5.
Say that Statement 4 has just changed COUNT
to 5.
The LOOP statement sends execution back to the DO WHILE
.
Will the loop body execute again?